﻿//using XW.Common;
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Text;

namespace XW.Core
{
    /// <summary>
    /// 单号生成模型
    /// </summary>
    public class VoucherGenModel
    {
        public string voucher { get; set; }
        /// <summary>
        /// 单号前缀
        /// </summary> 
        public string pre_code { get; set; }
        /// <summary>
        ///  单号
        /// </summary> 
        public string code { get; set; }
        /// <summary>
        /// 单号长度
        /// </summary> 
        public int number_len { get; set; }

        /// <summary>
        /// 最小
        /// </summary> 
        public int first_num { get; set; }
        /// <summary>
        /// 最大
        /// </summary> 
        public int last_num { get; set; }

        private string _currentCode = "";
        private int currentNum = 0;
        public string getNextCode() {
            if (currentNum  < first_num)
            {
                currentNum = first_num;
            }
            else
            {
                currentNum = currentNum + 1;
                if (currentNum > last_num)
                {
                    throw new Exception("已经最后一个了！");
                }
            }
            string no = "000000000000000000000000" + currentNum;
            _currentCode = code + no.Substring(no.Length - number_len);


            return _currentCode; 
        }
    }
}
